# simple calculator with exception handling

operator_set = {'+', 'add',
                '-', 'subtract',
                '*', 'multiply',
                '/', 'divide',
                '%', 'mod',
                '**', 'power',
                '//'}

def user_input():
    raw_input = []
    while True:
        try:
            num1 = float(input("Enter first number: "))
            raw_input.append(num1)
            num2 = float(input("Enter second number: "))
            raw_input.append(num2)
            operator = input("Enter operator: ")

        except Exception as e:
            print("Error : {}".format(str(e)))

        else:
            if operator in operator_set:
                raw_input.append(operator)
                break
            else:
                print("Please re-enter the operator.")
                raw_input = []

    return raw_input

def calculator(input):
    if(input[2] == '+' or input[2] == 'add'):
        return input[0] + input[1]
    elif(input[2] == '-' or input[2] == 'subtract'):
        return input[0] - input[1]
    elif(input[2] == '*' or input[2] == 'multipy'):
        return input[0] * input[1]
    elif(input[2] == '/' or input[2] == 'divide'):
        try:
            result = input[0] / input[1]
        except ZeroDivisionError:
            print("divisor can't be zero")
        else:
            return result
    elif(input[2] == '%' or input[2] == 'mod'):
        return input[0] % input[1]
    elif(input[2] == '**' or input[2] =='power'):
        return input[0] ** input[1]
    else:
        return input[0] // input[1]

if __name__ == '__main__':
    result = calculator(user_input())
    print(result)